﻿using JzSport.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace JzSport.WebApp.Init
{
    public partial class Init : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ServiceResult<Config> configResult = new ConfigService().Get(ConfigCode.AccountId_Seed);
                if (configResult.Data == null)
                {
                    new ConfigService().Save(new Config()
                    {
                        Code = ConfigCode.AccountId_Seed,
                        Value = "10000"
                    });
                }

                Response.Write(string.Format("<b>创建账号种子:{0}</b><Br/>", ConfigCode.AccountId_Seed));

                for (int index = 0; index < 10; index++)
                {
                    string phone = string.Format("135000001{0:d2}", index);
                    //ServiceResult<Verifycode> vcResult = new VerifycodeService().Send4RegisterByPhone(phone);
                    ServiceResult<Account> result = new AccountService().Import(phone, "123456");

                    if (result.ErrorCode == ErrorCode.NoError)
                    {
                        Response.Write(string.Format("<b>导入账号,id:{0},phone:{1}</b><Br/>", result.Data.Id, phone));
                    }
                    else
                    {
                        Response.Write(string.Format("<b>导入账号失败,phone:{0}</b><Br/>", phone));
                    }
                }


                // 创建活动类别
                BaseDataService bdService = new BaseDataService();
                BaseDataSummary summary = new BaseDataSummary();
                summary.Id = new Guid("{10C29F5D-F4CC-4043-AF2B-70C0BFB81621}");
                summary.Code = "ActivityCategory";
                summary.Caption = "活动类别";
                summary.Changeset = 1;
                summary.IsEnable = true;
                bdService.SaveSummary(summary);
                //羽毛球，足球，篮球，网球，排球，台球，气排球，乒乓球，自行车，户外拓展，攀岩
                string[] acCodes = new string[]{"AC001",
                    "AC002",
                    "AC003",
                    "AC004",
                    "AC005",
                    "AC006",
                    "AC007",
                    "AC008",
                    "AC009",
                    "AC010",
                    "AC011"
                };
                string[] acCaptions = new string[]{"羽毛球",
                    "足球",
                    "篮球",
                    "网球",
                    "排球",
                    "台球",
                    "气排球",
                    "乒乓球",
                    "自行车",
                    "户外拓展",
                    "攀岩"
                };
                for (int index = 0; index < acCodes.Length; index++)
                {
                    BaseDataItem item = new BaseDataItem();
                    item.Id = Guid.NewGuid();
                    item.Caption = acCaptions[index];
                    item.Code = acCodes[index];
                    item.SummaryId = summary.Id;
                    item.Order = index;
                    bdService.SaveItem(item);
                    Response.Write(string.Format("<b>创建活动类别,code:{0},caption:{1}</b><br/>", acCodes[index], acCaptions[index]));
                }
            }
        }
    }
}